package com.lcc.util;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.MimeMessageHelper;

import java.io.File;

/**
 * 发送邮件给别人工具类
 */
public class sendEmailToUserUtil {

    public static SimpleMailMessage sendToUser(){
        String code = EmailRandomUtil.randomNumBuilder();
        //创建邮件对象
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //设置邮件主题
        mailMessage.setSubject("验证码发送");
        //设置正文
        mailMessage.setText("您的验证码信息为：<strong>" + code + "</strong>,当前验证码有效时长为<strong>5分钟</strong>,请尽快进行登录验证,如非本人操作，请忽视！");
        //设置收件人邮箱
        mailMessage.setTo("480313990@qq.com");
        //设置发件人邮箱(与配置文件设置的qq邮箱一致)
        mailMessage.setFrom("507834010@qq.com");
        return mailMessage;
    }

    public static void sendToUser2(MimeMessageHelper helper){
        String code = EmailRandomUtil.randomNumBuilder();
        try{
            //设置邮件主题
            helper.setSubject("验证码发送");
            //设置正文
            helper.setText("您的验证码信息为：<strong>" + code + "</strong>,当前验证码有效时长为<strong>5分钟</strong>,请尽快进行登录验证,如非本人操作，请忽视！",true);
            helper.addAttachment("美女",new File("C:\\Users\\Administrator\\Pictures\\Camera Roll\\001.jpeg"));
            //设置收件人邮箱
            helper.setTo("480313990@qq.com");
            //设置发件人邮箱(与配置文件设置的qq邮箱一致)
            helper.setFrom("507834010@qq.com");
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
}
